<template>
    <div class="JoinFairButton">
        <el-button  
        @click="handleJoinJobFair"
        :style="{
            height: height,
            display: 'block', 
            margin: '0 auto',}" 
        :type="type" 
        :size="size"
        >进入会场</el-button>

         <!-- 参会确认框 -->
        <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
        <span>您还未参加此招聘会，是否一键报名？</span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleJoinJobFair(true)">一键报名</el-button>
        </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
  props:['size', 'height', 'info', 'jobFairId', 'type'],
  mounted(){
  },
  methods:{
      async handleJoinJobFair(apply=false){
        if(this.$store.state.home.isLogin == false){
            this.$router.push({path: `/videolobby/${this.jobFairId}/0`})
            return;
        }
        if(this.info.status == 0){
            this.$message.error('该招聘会已结束');
            return;
        }
        if(this.info.status == 2){
            this.$message.error('该招聘会未开始');
            return;
        }
        if(this.roleId == '0'){
            this.$router.push({path: `/videolobby/${this.jobFairId}/1`})
            return;
        }else if(apply == true){
            let res = await this.$store.dispatch('jobFairAppliedIsApplied', {
                jobFairId: this.jobFairId,
                userId: this.globalUserInfo.userId,
                roleId: this.roleId,
                comId: this.globalUserInfo.company.comId,
                apply,
            })
            console.log(res)
            if(res.code==0){
                this.dialogVisible = false;
                this.$message.success(res.msg);
            }
            
            
            return;

        }else if(this.roleId == '1'){
            let res = await this.$store.dispatch('jobFairAppliedIsApplied', {
                jobFairId: this.jobFairId,
                userId: this.globalUserInfo.userId,
                roleId: this.roleId,
                comId: this.globalUserInfo.company.comId,
                apply,
            })
            console.log(res)
            if(res.code == 0){
                this.$router.push({path: `/videolobby/${this.jobFairId}/0`})
                return;
            }
            if(res.msg !== '企业正在审核中，请耐心等待'){
                this.dialogVisible = true;
            }

        }
      
    },
    handleClose(done) {
        this.$confirm('确认关闭？')
        .then(_ => {
        done();
        })
        .catch(_ => {});
    }

  },
  data(){
    return {
      dialogVisible: false,
    }
  },
  computed: {
    roleId () {
      return this.$store.state.home.globalUserInfo.roleId
    }, 
    globalUserInfo () {
      return this.$store.state.home.globalUserInfo
    },
  },
}
</script>

<style lang="less">
.JoinFairButton {

}
</style>
